<template>
  <div class="app-container1 show-back-class">
    <div style="width: 100%;height: 60px;border-bottom: #1C97FF 1px solid;padding:  10px 20px;display: flex;">
      <img style="width: 340px; height: 40px; margin-right: 20px;" src="@/assets/bigScreen/index/LOGO.jpg" alt="">
      <big-tab-Bar />
    </div>
    <div class="content-bottom">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="名称" prop="name">
            <el-input v-model="queryParams.name"
            placeholder="请输入名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
            <el-option class="index-option" v-for="dict in $store.state.factorDict.statusOptions"
                       :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['factor:standardStage:add']" >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" icon="el-icon-refresh" size="mini" @click="handleClearCache" >清理缓存</el-button>
        </el-col>
	    <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
      </el-row>
      <el-table border
                v-loading="loading"
                :data="standardStageList"
                row-key="id"
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                :height="tableHeight"
      >
        <el-table-column label="序号" align="center" type="index" width="50" />
        <el-table-column label="名称" align="left" prop="name" />
        <el-table-column label="类型" align="center" prop="level" width="100">
          <template slot-scope="scope">
            {{selectDictLabelDefault($store.state.factorDict.standardStageTypeOptions, scope.row.type)}}
          </template>
        </el-table-column>
        <el-table-column label="排序" align="center" prop="orderNum" width="100"/>
        <el-table-column label="状态" align="center" prop="status" width="80">
          <template slot-scope="scope">
            {{selectDictLabelDefault($store.state.factorDict.statusOptions, scope.row.status)}}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                       v-hasPermi="['factor:standardStage:edit']" >修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                       v-hasPermi="['factor:standardStage:remove']" >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <change-form ref="changeFormRef" @getList="getList" :standard-stage-options="standardStageOptions"/>
    </div>
  </div>
</template>

<script>
import { listStandardStage, getStandardStage, delStandardStage, addStandardStage, updateStandardStage, clearStandardStageCache } from "@/api/factor/standardStage";
import ChangeForm from "./changeForm"
import bigTabBar from '@/views/components/bigTabBar/index'
export default {
  name: "StandardStage",
  components:{
    ChangeForm,bigTabBar
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      showSearch: true,
      // 项目标准阶段管理表格数据
      standardStageList: [],
      standardStageOptions: [],
      // 查询参数
      queryParams: {
        parentId: null,
        name: null,
        type: null,
        status: null,
        orderNum: null,
      },
      tableHeight: '',
    };
  },
  created() {
    this.tableHeight = window.innerHeight - 220;
    this.getList();
  },
  methods: {
    /** 查询项目标准阶段管理列表 */
    getList() {
      this.loading = true;
      listStandardStage(this.queryParams).then(response => {
        this.standardStageList = this.handleTree(response.rows, "id", "parentId");
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      listStandardStage({status:1}).then(response => {
        this.standardStageOptions = [];
        const data = { id: 0, name: '顶级节点', children: [] };
        data.children = this.handleTree(response.rows, "id", "parentId");
        this.standardStageOptions.push(data);
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.getTreeselect();
      this.$refs.changeFormRef.handleAdd();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.getTreeselect();
      this.$refs.changeFormRef.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delStandardStage(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    handleClearCache(){
      clearStandardStageCache().then(response => {
        if (response.code === '200') {
          this.msgSuccess("清理成功");
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.app-container1{
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #000D17;
  // background: url("../../assets/bg2.jpg") no-repeat;
  // background-size: 100% 100%;
}
.content-bottom{
  width: 100%;
  height: calc(100% - 60px);
  background-color: #000D17;
  padding: 20px;
}
</style>